﻿package mortal.game.scene3D.display3d.text3d.staticText3d
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.event.*;
    import mortal.game.scene3D.display3d.text3d.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.action.*;

    public class Stext3DBox extends Pivot3D
    {
        public var list:Vector.<SText3D>;
        public var startFrame:uint;
        private var _x:Number = 0;
        private var _y:Number = 0;
        private var _z:Number = 0;
        private var _targetBox:Pivot3D;
        private var _place:Stext3DPlace;
        private var _setTextWidth:Number = 0;
        private var _targetVector:Vector.<Number>;
        private var _ix:int;
        private var _iy:int;
        private var _iz:int;
        private var _iw:int;
        private var _isShowing:Boolean = true;
        private var _gx:Number = 0;
        private var _gy:Number = 0;
        private var _gz:Number = 0;
        private var _result:Vector3D;
        private var _preframe:int = -1;
        private var _action0:ActionMoveBase;
        private var _action1:ActionMoveBase;
        private var _action2:ActionMoveBase;
        private var _curAction:ActionMoveBase;
        private var _updataPos:Boolean = false;
        private static var _temp0:Vector3D = new Vector3D(0, 0, 0, 1);

        public function Stext3DBox(param1:String)
        {
            this._result = new Vector3D();
            super(param1);
            this.enabledPool = false;
            return;
        }// end function

        override public function set x(param1:Number) : void
        {
            this._x = param1;
            this._updataPos = true;
            return;
        }// end function

        override public function set y(param1:Number) : void
        {
            this._y = param1;
            this._updataPos = true;
            return;
        }// end function

        override public function set z(param1:Number) : void
        {
            this._z = param1;
            this._updataPos = true;
            return;
        }// end function

        override public function get x() : Number
        {
            return this._x;
        }// end function

        override public function get y() : Number
        {
            return this._y;
        }// end function

        override public function get z() : Number
        {
            return this._z;
        }// end function

        public function get textWidth() : Number
        {
            return this._setTextWidth;
        }// end function

        public function set textWidth(param1:Number) : void
        {
            this._setTextWidth = param1;
            return;
        }// end function

        private function updatePos(event:Event = null) : void
        {
            this._updataPos = true;
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            var _loc_3:Vector3D = null;
            var _loc_2:* = TimeControler.stageFrame - this.startFrame;
            if (this._preframe == _loc_2)
            {
                return;
            }
            this._preframe = _loc_2;
            if (this._updataPos)
            {
                if (this._targetBox)
                {
                    _loc_3 = this._targetBox.getPosition(false, _temp0);
                    _loc_3.x = _loc_3.x + this._x;
                    _loc_3.y = _loc_3.y + this._y;
                    _loc_3.z = _loc_3.z + this._z;
                    _loc_3 = Device3D.view.transformVector(_loc_3);
                    this._gx = _loc_3.x;
                    this._gy = _loc_3.y;
                    this._gz = _loc_3.z;
                }
                else
                {
                    this._gx = this._x;
                    this._gy = this._y;
                    this._gz = this._z;
                }
                this._updataPos = false;
            }
            if (this._curAction.update(_loc_2, this._result))
            {
                this._targetVector[this._ix] = this._gx + this._result.x;
                this._targetVector[this._iy] = this._gy + this._result.y;
                this._targetVector[this._iz] = this._gz;
                this._targetVector[this._iw] = -this._result.z;
            }
            else
            {
                SText3DFactory.instance.disposeText3D(this);
            }
            return;
        }// end function

        public function set place(param1:Stext3DPlace) : void
        {
            this._place = param1;
            this._ix = this._place.placeId * 4;
            this._iy = this._ix + 1;
            this._iz = this._ix + 2;
            this._iw = this._ix + 3;
            this._targetVector = this._place.targetVector.list;
            this._updataPos = true;
            return;
        }// end function

        public function get place() : Stext3DPlace
        {
            return this._place;
        }// end function

        public function reInit(param1:int, param2:Vector.<SText3D>, param3:Stext3DPlace, param4:Number, param5:Pivot3D, param6:ActionVo) : void
        {
            var _loc_7:Vector3D = null;
            this.list = param2;
            this.startFrame = param1;
            this.textWidth = param4;
            this.place = param3;
            this._curAction = this.getAction(param6);
            if (!param6.isfollowMoving)
            {
                _loc_7 = param5.getPosition(false, _temp0);
                _loc_7 = Device3D.view.transformVector(_loc_7);
                this._x = _loc_7.x;
                this._y = _loc_7.y;
                this._z = _loc_7.z;
                param5 = null;
            }
            this._targetBox = param5;
            this.updatePos(null);
            this.show();
            if (this.parent == null)
            {
                Global3D.scene.addChild(this);
            }
            this.update();
            return;
        }// end function

        private function getAction(param1:ActionVo) : ActionMoveBase
        {
            var _loc_2:ActionMoveBase = null;
            if (param1.type == 1)
            {
                if (!this._action0)
                {
                    this._action0 = new Action0MoveFun();
                }
                _loc_2 = this._action0;
            }
            else if (param1.type == 2)
            {
                if (!this._action2)
                {
                    this._action2 = new Action2MoveFun();
                }
                _loc_2 = this._action2;
            }
            else
            {
                if (!this._action1)
                {
                    this._action1 = new Action1MoveFun();
                }
                _loc_2 = this._action1;
            }
            _loc_2.vo = param1;
            _loc_2.changeScale = param1.changeScale;
            return _loc_2;
        }// end function

        public function show() : void
        {
            this._targetVector[this._iw] = -this._result.z;
            this._isShowing = true;
            return;
        }// end function

        public function hide() : void
        {
            this._targetVector[this._iw] = -1000;
            this._isShowing = false;
            return;
        }// end function

        public function clear(param1:Boolean) : void
        {
            if (this.place)
            {
                this.hide();
                this.place.targetVector.clearSplace(this.place);
            }
            var _loc_2:int = 0;
            this._z = 0;
            var _loc_2:* = _loc_2;
            this._y = _loc_2;
            this._x = _loc_2;
            if (param1)
            {
                this._targetBox = null;
                if (this.parent)
                {
                    this.parent.removeChild(this);
                }
            }
            return;
        }// end function

    }
}
